//
//  XLHostSideNewPersonCell.m
//  XiangLove
//
//  Created by 李传坤 on 2018/5/28.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHostSideNewPersonCell.h"
#import "NSString+Ext.h"

@implementation XLHostSideNewPersonCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]){
        [self addLoadViews];
    }
    return self;
}
-(void)addLoadViews
{
    _headerImageView                        = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, (XQScreenW-5)/2, 220)];
//    _hostImgView.userInteractionEnabled = YES;
//    _hostImgView.clipsToBounds          = YES;
//    _hostImgView.contentMode            = UIViewContentModeScaleAspectFill;
//    _hostImgView.autoresizingMask       = UIViewAutoresizingFlexibleWidth;
//    [_hostImgView setContentScaleFactor:[[UIScreen mainScreen] scale]];
    [self addSubview:_headerImageView];
    [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(2);
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
         make.bottom.equalTo(self.contentView.mas_bottom).offset(-23);
        
    }];
    _nickNameLabel                     = [[UILabel alloc] init];
    _nickNameLabel.textColor           = kBlackColor;
    _nickNameLabel.font                = KSetBoldFont(13);
    _nickNameLabel.backgroundColor = kClearColor;
    [self addSubview:_nickNameLabel];
    [self.nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-2);
        make.left.equalTo(self.contentView.mas_left).offset(5);
        make.right.equalTo(self.contentView.mas_right).offset(-30);
        
    }];
    self.levelImage = [[UIImageView alloc]init];
    
    [self addSubview:_levelImage];
    
    _stateBgView            = [[UIView alloc] init];
    _stateBgView.backgroundColor     = RGBA_HEX(0x000000, 0.4);
    _stateBgView.layer.masksToBounds = YES;
    _stateBgView.layer.cornerRadius  = 3;
    _stateBgView.layer.borderColor   = kWhiteColor.CGColor;
    //    _stateBgView.layer.borderWidth   = 0.5;
    [self addSubview:_stateBgView];
    [_stateBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImageView.mas_top).offset(5);
        make.right.equalTo(self.headerImageView.mas_right).offset(-5);
        make.size.mas_equalTo(CGSizeMake(30, 18));
    }];
    
    
    _hostState                   = [[UILabel alloc] init];
    _hostState.backgroundColor   = kClearColor;
    _hostState.textColor         = kWhiteColor;
    _hostState.font              = kSetFont(10);
    _hostState.textAlignment     = NSTextAlignmentCenter;
    [_stateBgView addSubview:_hostState];
    [self.hostState mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.headerImageView.mas_right).offset(-10);
        make.top.equalTo(self.headerImageView.mas_top).offset(8);
    }];
    
    
    
   
}

-(void)setDataModels:(XLHostSideTuijianModel *)dataModels
{
    if (_dataModels != dataModels) {
        _dataModels = dataModels;
    }
    [self.headerImageView setImageWithURL:[NSURL URLWithString:dataModels.HeadImg] placeholder:[UIImage imageWithColor:RGB(255, 255, 255)]];
    self.nickNameLabel.text  = dataModels.NickName;_nickNameLabel.font = [UIFont systemFontOfSize:14];
    CGFloat width = [self.nickNameLabel.text sizeWidthsFont:15 andHeight:20];
    if (width > self.frame.size.width - 95) {
        width =  self.frame.size.width - 95;
    }
    _levelImage.frame = CGRectMake(self.frame.size.width - 28, self.frame.size.height - 17, 26, 13);
    [self.levelImage setImageWithURL:[NSURL URLWithString:dataModels.LevelIcon] placeholder:nil];
    
    if ([dataModels.OnlineStatus isEqualToString:@"0"]) {
        //        self.hostState.text = @"离线";
        //        self.onlineState.backgroundColor = RGB_HEX(0x9395a2);
        self.hostState.text = @"离线";
//        self.stateBgView.hidden = YES;
    }else if ([dataModels.OnlineStatus isEqualToString:@"1"])
    {
//        self.stateBgView.hidden = NO;
        self.hostState.text = @"在线";
//        self.onlineState.backgroundColor = RGB_HEX(0x2ace46);
    }else if ([dataModels.OnlineStatus isEqualToString:@"2"] || [dataModels.OnlineStatus isEqualToString:@"3"]){
//        self.stateBgView.hidden = NO;
        self.hostState.text = @"在线";
//        self.onlineState.backgroundColor = RGB_HEX(0x2ace46);
    }else{
//        self.stateBgView.hidden = NO;
        self.hostState.text = @"离线";
//        self.stateBgView.backgroundColor = RGB_HEX(0xff3131);
    }
    
}
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}

@end
